class EXAMPLE7
-- This example show how use a expander, sn sbox and a tree.
-- Also show how use the class IUP_CONFIG to store user preferences.

inherit
	IUP_INTERFACE

create {ANY}
   make

feature {ANY}

	cfg: IUP_CONFIG
	
   make
      local
 			gui: IUP
			i: STRING
			b1, b2, b3, b4, b5: IUP_BUTTON
			sb: IUP_SBOX
			bx: IUP_BACKGROUND_BOX
			ex: IUP_EXPANDER
			tr: IUP_TREE
			h1, h2: IUP_HBOX
			v: IUP_VBOX
			w: IUP_DIALOG
			ri: INTEGER
      do
			gui := iup_open
			gui.load_images -- Load the predefined images at IUP stock.

			-- Load config file
			create cfg.config
			cfg.set_app_name("example7")
			ri := cfg.load

			-- Create the buttons to the expander
			create b1.button("")
			b1.set_image("IUP_FileNew")
			create b2.button("")
			b2.set_image("IUP_FileOpen")
			create b3.button("")
			b3.set_image("IUP_FileSave")

			create h1.hbox({ARRAY[IUP_WIDGET]} << b1, b2, b3 >>)
			create bx.background_box(h1)
			create ex.expander(bx)
			ex.set_title("Buttons")
			ex.set_collapsed

			-- Create the buttons
	      create b4.button("Button inside Sbox")
			create b5.button("Other button")

			-- The sbox
			create sb.sbox(b4)

			-- Put sb and b2 inside an horizontal box.
	      create h2.hbox({ARRAY[IUP_WIDGET]} << sb, b5 >>)
			h2.set_gap(10)
			h2.set_margin(10, 10)

			-- Create the tree
			create tr.tree

			-- Put all inside a vertical box
			create v.vbox({ARRAY[IUP_WIDGET]} << ex, h2, tr >>)

			-- Create the window.
	      create w.dialog(v)
			w.set_title("Example 7")
			w.set_cb_close(agent close)

			if ri.is_equal(0) then
				cfg.show_dialog(w, "main")
			else
				i := w.show
			end

			-- Add items to the tree (should be do after map)
			tr.set_title_at("Figures", 0)
			tr.add_leaf_at("other", 0)
			tr.add_branch_at("triangle", 1)
			tr.add_leaf_at("equilateral", 2)
			tr.add_leaf_at("isoceles", 3)
			tr.add_leaf_at("scalenus", 4)
			tr.insert_branch_at("parallelogram", 2)
			tr.add_leaf_at("square", 6)
			tr.add_leaf_at("diamond", 7)
			tr.insert_branch_at("2D", 6)
			tr.insert_branch_at("3D", 9)
						
         gui.main_loop
			gui.close
      end

	close (dlg: IUP_DIALOG): STRING
		local
			i: INTEGER
		do
			cfg.save_dialog(dlg, "main")
			i := cfg.save

			-- We should destroy the config object.
			cfg.destroy
			
			Result := "IUP_DEFAULT"
		end

end -- class EXAMPLE7
